'use strict';

/**
 * copyright (c) 2017-2023 厦门风领科技有限公司
 * https://www.fengling.cn/
 * 
 * 初始化管理器
 * zengbinsi
 * 2020-08-24
 */


import path from 'path';
import pathUtil from '../libs/utils/path-utils';
import fileUtil from '../libs/utils/file-utils';
import { callSequence } from '../libs/utils/function-call-seq';
const srcPath = pathUtil.getPathInTemplateAssets(path.join('bundles', 'framework', 'other', 'find-path-astar'));
const dstPath = pathUtil.getPathInAssets(path.join('bundles', 'framework', 'other', 'find-path-astar'));




// 初始化目录
const initDir = (callback?: Function) => {
    pathUtil.mkdirsSyncInAssets(path.join('bundles', 'framework', 'other', 'find-path-astar'), callback);
};

const initTilePoint = (callback?: Function) => {
    console.log(`[tool-box]import TilePoint.ts...`);
    fileUtil.copy(path.join(srcPath, 'TilePoint.tsz'), path.join(dstPath, 'TilePoint.ts'));
    console.log(`[tool-box]import TilePoint.ts successed!`);
    callback && callback();
};

const initTile = (callback?: Function) => {
    console.log(`[tool-box]import Tile.ts...`);
    fileUtil.copy(path.join(srcPath, 'Tile.tsz'), path.join(dstPath, 'Tile.ts'));
    console.log(`[tool-box]import Tile.ts successed!`);
    callback && callback();
};

const initAStar = (callback?: Function) => {
    console.log(`[tool-box]import AStar.ts...`);
    fileUtil.copy(path.join(srcPath, 'AStar.tsz'), path.join(dstPath, 'AStar.ts'));
    console.log(`[tool-box]import AStar.ts successed!`);
    callback && callback();
};


export const initFileOtherFindPathAStart = (callback?: Function) => {
    return callSequence([initDir, initTilePoint, initTile, initAStar, async (cb?: Function) => {
        await pathUtil.refreshAsset(`db://assets/bundles/framework/other/find-path-astar/`);
        cb && cb();
    }, callback]);
};